package conf2.model;

import conf2.util.Arr;
import java.util.EnumMap;
import java.util.Map;
import static conf2.model.ETerritory.*;

class WorldMap {

    private static class Neighbors {

        ETerritory[] lightForward = new ETerritory[0];
        ETerritory[] darkForward = new ETerritory[0];
        ETerritory[] sideways = new ETerritory[0];
        ETerritory[] adjacent = new ETerritory[0];
        ETerritory[] lightBackwards = new ETerritory[0];
        ETerritory[] darkBackwards = new ETerritory[0];
    }
    private static Map<ETerritory, Neighbors> neighbors = new EnumMap<ETerritory, Neighbors>(ETerritory.class);
    

    static {
        Neighbors n;

        n = new Neighbors();
        n.lightForward = new ETerritory[]{ARTHEDAIN, CARDOLAN};
        n.darkBackwards = n.lightForward;
        n.adjacent = n.lightForward;
        neighbors.put(SHIRE, n);

        n = new Neighbors();
        n.lightForward = new ETerritory[]{RHUDAUR, EREGION};
        n.darkForward = new ETerritory[]{SHIRE};
        n.lightBackwards = n.darkForward;
        n.darkBackwards = n.lightForward;
        n.sideways = new ETerritory[]{CARDOLAN};
        n.adjacent = new ETerritory[]{RHUDAUR, EREGION, SHIRE, CARDOLAN};
        neighbors.put(ARTHEDAIN, n);

        n = new Neighbors();
        n.lightForward = new ETerritory[]{EREGION, ENEDWAITH};
        n.darkForward = new ETerritory[]{SHIRE};
        n.lightBackwards = n.darkForward;
        n.darkBackwards = n.lightForward;
        n.sideways = new ETerritory[]{ARTHEDAIN};
        n.adjacent = new ETerritory[]{EREGION, ENEDWAITH, SHIRE, ARTHEDAIN};
        neighbors.put(CARDOLAN, n);

        n = new Neighbors();
        n.lightForward = new ETerritory[]{HIGHPASS, MISTYMTS};
        n.darkForward = new ETerritory[]{ARTHEDAIN};
        n.lightBackwards = n.darkForward;
        n.darkBackwards = n.lightForward;
        n.sideways = new ETerritory[]{EREGION};
        n.adjacent = new ETerritory[]{HIGHPASS, MISTYMTS, ARTHEDAIN, EREGION};
        neighbors.put(RHUDAUR, n);

        n = new Neighbors();
        n.lightForward = new ETerritory[]{MISTYMTS, MORIA, FANGORN};
        n.darkForward = new ETerritory[]{ARTHEDAIN, CARDOLAN};
        n.lightBackwards = n.darkForward;
        n.darkBackwards = new ETerritory[]{MISTYMTS, MORIA};
        n.sideways = new ETerritory[]{RHUDAUR, ENEDWAITH};
        n.adjacent = new ETerritory[]{MISTYMTS, MORIA, RHUDAUR, ENEDWAITH, ARTHEDAIN, CARDOLAN};
        neighbors.put(EREGION, n);

        n = new Neighbors();
        n.lightForward = new ETerritory[]{MORIA, GAPOFROHAN};
        n.darkForward = new ETerritory[]{CARDOLAN};
        n.lightBackwards = n.darkForward;
        n.darkBackwards = n.lightForward;
        n.sideways = new ETerritory[]{EREGION};
        n.adjacent = new ETerritory[]{MORIA, GAPOFROHAN, CARDOLAN, EREGION};
        neighbors.put(ENEDWAITH, n);

        n = new Neighbors();
        n.lightForward = new ETerritory[]{MIRKWOOD};
        n.darkForward = new ETerritory[]{RHUDAUR};
        n.lightBackwards = n.darkForward;
        n.darkBackwards = n.lightForward;
        n.adjacent = new ETerritory[]{MIRKWOOD, RHUDAUR};
        neighbors.put(HIGHPASS, n);

        n = new Neighbors();
        n.lightForward = new ETerritory[]{MIRKWOOD, FANGORN};
        n.darkForward = new ETerritory[]{RHUDAUR, EREGION};
        n.lightBackwards = n.darkForward;
        n.darkBackwards = n.lightForward;
        n.adjacent = new ETerritory[]{MIRKWOOD, FANGORN, RHUDAUR, EREGION};
        neighbors.put(MISTYMTS, n);

        n = new Neighbors();
        n.lightForward = new ETerritory[]{FANGORN, ROHAN};
        n.darkForward = new ETerritory[]{EREGION, ENEDWAITH};
        n.lightBackwards = n.darkForward;
        n.darkBackwards = n.lightForward;
        n.adjacent = new ETerritory[]{FANGORN, ROHAN, EREGION, ENEDWAITH};
        neighbors.put(MORIA, n);

        n = new Neighbors();
        n.lightForward = new ETerritory[]{ROHAN};
        n.darkForward = new ETerritory[]{ENEDWAITH};
        n.lightBackwards = n.darkForward;
        n.darkBackwards = n.lightForward;
        n.adjacent = new ETerritory[]{ROHAN, ENEDWAITH};
        neighbors.put(GAPOFROHAN, n);

        n = new Neighbors();
        n.lightForward = new ETerritory[]{DAGORLAD, FANGORN};
        n.darkForward = new ETerritory[]{HIGHPASS, MISTYMTS};
        n.lightBackwards = n.darkForward;
        n.darkBackwards = new ETerritory[]{DAGORLAD};
        n.sideways = new ETerritory[]{FANGORN};
        n.adjacent = new ETerritory[]{DAGORLAD, FANGORN, HIGHPASS, MISTYMTS};
        neighbors.put(MIRKWOOD, n);

        n = new Neighbors();
        n.lightForward = new ETerritory[]{DAGORLAD, GONDOR, ROHAN};
        n.darkForward = new ETerritory[]{MISTYMTS, MORIA};
        n.lightBackwards = n.darkForward;
        n.darkBackwards = new ETerritory[]{DAGORLAD, GONDOR};
        n.sideways = new ETerritory[]{MIRKWOOD, ROHAN};
        n.adjacent = new ETerritory[]{DAGORLAD, GONDOR, ROHAN, MIRKWOOD, MISTYMTS, MORIA};
        neighbors.put(FANGORN, n);

        n = new Neighbors();
        n.lightForward = new ETerritory[]{GONDOR};
        n.darkForward = new ETerritory[]{MORIA, GAPOFROHAN};
        n.lightBackwards = n.darkForward;
        n.darkBackwards = n.lightForward;
        n.sideways = new ETerritory[]{FANGORN};
        n.adjacent = new ETerritory[]{GONDOR, MORIA, GONDOR, FANGORN};
        neighbors.put(ROHAN, n);

        n = new Neighbors();
        n.lightForward = new ETerritory[]{MORDOR};
        n.darkForward = new ETerritory[]{MIRKWOOD, FANGORN};
        n.lightBackwards = n.darkForward;
        n.darkBackwards = n.lightForward;
        n.sideways = new ETerritory[]{GONDOR};
        n.adjacent = new ETerritory[]{MORDOR, MIRKWOOD, FANGORN, GONDOR};
        neighbors.put(DAGORLAD, n);

        n = new Neighbors();
        n.lightForward = new ETerritory[]{MORDOR};
        n.darkForward = new ETerritory[]{ROHAN, FANGORN};
        n.lightBackwards = n.darkForward;
        n.darkBackwards = n.lightForward;
        n.sideways = new ETerritory[]{DAGORLAD};
        n.adjacent = new ETerritory[]{MORDOR, ROHAN, FANGORN, DAGORLAD};
        neighbors.put(GONDOR, n);

        n = new Neighbors();
        n.darkForward = new ETerritory[]{DAGORLAD, GONDOR};
        n.lightBackwards = n.darkForward;
        n.adjacent = n.darkForward;
        neighbors.put(MORDOR, n);

    }

    static ETerritory[] getAdjacent(ETerritory t) {
        return neighbors.get(t).adjacent;
    }

    static ETerritory[] getSideways(ETerritory t) {
        return neighbors.get(t).sideways;
    }

    static ETerritory[] getLightForward(ETerritory t) {
        return neighbors.get(t).lightForward;
    }

    static ETerritory[] getDarkForward(ETerritory t) {
        return neighbors.get(t).darkForward;
    }

    static ETerritory[] getLightBackwards(ETerritory t) {
        return neighbors.get(t).lightBackwards;
    }

    static ETerritory[] getDarkBackwards(ETerritory t) {
        return neighbors.get(t).darkBackwards;
    }

    static boolean isAdjacentTo(ETerritory from, ETerritory to) {
        return Arr.contains(to, neighbors.get(from).adjacent);
    }

    static boolean isSidewaysTo(ETerritory from, ETerritory to) {
        return Arr.contains(to, neighbors.get(from).sideways);
    }

    static boolean isLightForwardTo(ETerritory from, ETerritory to) {
        return Arr.contains(to, neighbors.get(from).lightForward);
    }

    static boolean isDarkForwardTo(ETerritory from, ETerritory to) {
        return Arr.contains(to, neighbors.get(from).darkForward);
    }
}
